# -*- coding:utf-8 -*-

'''
PROJECT_NAME : auth_demo
file    : app
author  : 1032162439@qq.com
date    : 2022-09-08 17:52
IDE     : PyCharm
'''
from flask import Flask, request, make_response
from datetime import datetime, timedelta


app = Flask(__name__)


@app.route('/set_cookie')
def set_cookie():
    """
    设置cookie
    :return:
    """
    resp = make_response('set cookie success')
    resp.set_cookie('user', 'zhangsan', max_age=30, path='/source', domain='testsite.api', httponly=True)
    return resp


@app.route('/source')
def source():
    """
    资源目录
    :return:
    """
    user = request.cookies.get('user')
    print(user)
    if not user:
        return '无权限'
    else:
        return '有权访问'


@app.route('/content')
def content():
    user = request.cookies.get('user')
    print(user)
    if not user:
        return '无权限'
    else:
        return '有权访问'


if __name__ == '__main__':
    # 启动app, 开启调试模式
    app.run(debug=True)

